package com.flyou.ccnucenter.ui.frgment;

import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyou.ccnucenter.Constant;
import com.flyou.ccnucenter.R;
import com.flyou.ccnucenter.ui.frgment.SchoolMessage.ActivityMessageFragment;
import com.flyou.ccnucenter.ui.frgment.SchoolMessage.NotficationMessageFragment;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import org.simple.eventbus.EventBus;

public class SchoolMEssageFragment extends BaseFragment {

    private View parentView;
    private SmartTabLayout mTabLayout;
    private ViewPager mViewPager;

    @Override
    protected View onCreatView(LayoutInflater inflater, ViewGroup container) {
        parentView=inflater.inflate(R.layout.fragment_school_beside, container, false);
        return parentView;
    }

    @Override
    protected void initData() {
        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getChildFragmentManager(), FragmentPagerItems.with(context)
                .add(getString(R.string.school_message), NotficationMessageFragment.class)
                .add(getString(R.string.edu_message), ActivityMessageFragment.class)
//                .add(getString(R.string.personal_message), PersonalMessageFragment.class)



                .create());
//        mViewPager.setOffscreenPageLimit(0);
        if(mViewPager.getAdapter() == null) {
            mViewPager.setAdapter(adapter);
        }

        mTabLayout.setViewPager(mViewPager);
        mTabLayout.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                if (position>0) {
                    EventBus.getDefault().post("", Constant.DISABLE_MENU);
                }
                else {
                    EventBus.getDefault().post("", Constant.ENABLE_MENU);
                }
                super.onPageSelected(position);
            }
        });
    }

    @Override
    protected void initView() {
        mTabLayout= (SmartTabLayout) parentView.findViewById(R.id.viewpagertab);
        mViewPager= (ViewPager) parentView.findViewById(R.id.viewpager);

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().post("", Constant.ENABLE_MENU);
    }
}
